feat(oiiotool): Add thumbnail get/set commands and fix TGA thumbnail I/O#5236
feat(oiiotool): Add thumbnail get/set commands and fix TGA thumbnail I/O#5236jinhgkim wants to merge 8 commits into
Conversation
Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
Encode the embedded thumbnail the same way as the main image: bottom-up scanlines, deassociated alpha, and BGR(A) channel order. The original implementation rather dumped the raw in-memory buffer, which left the thumbnail flipped, R/B-swapped, and premultiplied. Also clamp an oversized thumbnail to 255 rather than 256: each postage-stamp dimension is a single byte, so 256 wrapped to 0 and the thumbnail was silently dropped on read. Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
TGA stores unassociated alpha, but OIIO keeps it associated in memory. `readimg()` converts on read; `get_thumbnail()` did not, so RGBA thumbnails came back too bright. Apply the same `associateAlpha()` conversion to the thumbnail. get_thumbnail() is moved below associateAlpha() so it can call it without a forward declaration. Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
Assisted-by: Claude Code / opus-4.8 Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
54e6a14 to
2b002d9
Compare
Signed-off-by: Jinnie Kim <jinhgkim@gmail.com>
2b002d9 to
c589b11
Compare
|
During the CI run, a TGA thumbnail test failed because I added Let me know what you think. Also, fyi, I have broken down the commits into logical steps with some details in the commit message. |
lgritz
left a comment
There was a problem hiding this comment.
This more or less LGTM. I didn't click approve only because I want to give you the chance to respond to some of the comments I left, none of which are strictly required, but maybe you'll particularly want to do some of those things.
| If 0, an empty (0x0) image is pushed in its place instead, so a batch | ||
| script can continue; guard any subsequent output (see the example | ||
| below), since writing the empty image is itself an error. |
There was a problem hiding this comment.
Two things to consider here.
- I'm not sure how resilient anything downstream will be to a literal 0x0 image.
- Does it make more sense for a "handled failure" to be either (a) just leave the original full-size image on the stack, or (b) perform the equivalent of a --resize or --resample to a reasonable thumbnail-like resolution?
| ap.arg("--get-thumbnail") | ||
| .help("Extract an embedded thumbnail (options: fail=, index=)") | ||
| .OTACTION(action_get_thumbnail); | ||
| ap.arg("--set-thumbnail") | ||
| .help("Attach the top image as the thumbnail of the image below it") | ||
| .OTACTION(action_set_thumbnail); |
There was a problem hiding this comment.
I'm not sure I feel strongly about this, but want to throw it out there in case it resonates with you. Would you prefer "--thumbnail-get" and "--thumbnail-set" for the sake of ensuring that they are always next to each other in an alphabetical listing of commands?
We purposely picked --mulc so that it would be next to --mul in alphabetical listings for similar reason.
| bool | ||
| TGAInput::get_thumbnail(ImageBuf& thumb, int subimage) | ||
| { | ||
| if (m_ofs_thumb <= 0) | ||
| return false; // no thumbnail info | ||
|
|
There was a problem hiding this comment.
Can I ask why this function moved position in the file? That makes it hard to tell form the diffs exactly what changed. Or did it only move?
|
Just another suggestion I thought of while reviewing this, so I'll mention it here. Though you need not add it, maybe it's an item for a follow-up, or just to put on the list of extensions to consider for some day (maybe only after Do you think it would be useful to have a |
Description
Adds
oiiotoolcommands to extract and attach embedded thumbnails, and fixes TGA postage-stamp read/write bugs they exposed. This PR adresses #4889.Note that thumbnail support is uneven across formats:
get_thumbnailis implemented for PSD, camera RAW, and TGA, butset_thumbnailonly for TGA. So you can read thumbnails from several formats, yet TGA is the only format that writes an embedded thumbnail today. e.g.,input.exr ... --set-thumbnail -o out.exrsilently produces an EXR with no embedded thumbnail.Features:
oiiotool: add--get-thumbnailoiiotool: add-i:get_thumbnail=1oiiotool: add--set-thumbnailFixes:
write: encode thumbnail like the main image (bottom-up, deassociated alpha, BGR(A))read: applyassociateAlpha()Assisted-by: Claude Code / opus-4.8
Tests
New tests in
oiiotool-get-thumbnail,oiiotool-set-thumbnail,imagebuf_testChecklist:
and if I used AI coding assistants, I have an
Assisted-by: TOOL / MODELline in the pull request description above.
behavior.
PR, by pushing the changes to my fork and seeing that the automated CI
passed there. (Exceptions: If most tests pass and you can't figure out why
the remaining ones fail, it's ok to submit the PR and ask for help. Or if
any failures seem entirely unrelated to your change; sometimes things break
on the GitHub runners.)
fixed any problems reported by the clang-format CI test.
corresponding Python bindings. If altering ImageBufAlgo functions, I also
exposed the new functionality as oiiotool options.